<?php
namespace Admin\Controller;
class AddmodityController extends BaseController {
    public function index(){
        $Modity = M('cate');
        $rs = $Modity->select();
        $this->assign(rs,$rs);
        $this->display();
    }
    public function upload(){
       $user=session("logIn.username");  // session
       $config = array(
           'maxSize'    =>    3145728,    
           'rootPath'   =>    './Public/Uploads/',    
           'saveName'   =>    array('uniqid',''),    
           'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),    
           'autoSub'    =>    true,    
           'subName'    =>    array('date','Ymd'),
       );
       $upload = new \Think\Upload($config); // 实例化上传类
       $info = $upload->upload();
       if(!$info){
           $this->ajaxReturn($upload->getError());
       }else{
           $data = I('post.');
           foreach ( $info as $file){
               $data['pImg'] = $file['savepath'].$file['savename'];
           }
           $Addmodity = M('pro');
           $rs = $Addmodity->data($data)->add();
                   if(!empty($rs)){
                       $array = array('status'=>"1",'info'=>"添加成功",'url'=>U('Lommodity/index'));
                   }else{
                       $array = array('status'=>"0",'info'=>"添加失败",'url'=>U('Lommodity/index'));
                   }
           $this->ajaxReturn($array);
       }
    }
}
